import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import * as echarts from 'echarts'
import {store} from '@/store'
import zhCn from 'element-plus/es/locale/lang/zh-cn' // 引入中文语言包
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
const app = createApp(App)
app.config.globalProperties.$echarts = echarts

app.use(ElementPlus, {
  locale: zhCn // ✅ 设置为中文
})
app.use(router)
app.use(store)
// 此操作为了避免循环限制导致的ResizeObserver错误
// 忽略 ResizeObserver 错误
const isResizeObserverError = (error) => {
  return error.message && (
    error.message.includes('ResizeObserver loop completed with undelivered notifications') ||
    error.message.includes('ResizeObserver loop limit exceeded')
  )
}

// 重写 console.error
const originalConsoleError = console.error
console.error = function (...args) {
  if (args[0] && isResizeObserverError(args[0])) {
    return
  }
  originalConsoleError.apply(console, args)
}

// 重写 window.onerror
const originalOnError = window.onerror
window.onerror = function (message, source, lineno, colno, error) {
  if (message && typeof message === 'string' && (
    message.includes('ResizeObserver loop completed with undelivered notifications') ||
    message.includes('ResizeObserver loop limit exceeded')
  )) {
    return true // 阻止错误继续传播
  }
  if (originalOnError) {
    return originalOnError.apply(this, arguments)
  }
  return false
}

// 捕获未处理的 Promise 错误
window.addEventListener('unhandledrejection', event => {
  if (event.reason && isResizeObserverError(event.reason)) {
    event.preventDefault()
  }
})


app.mount('#app')
window.app = app
